package v1

import (
	modelJielong "youdu/model/jielong"

	"github.com/go-gormigrate/gormigrate/v2"
	"gorm.io/gorm"
)

// 本迁移文件是一些 demo 示例，和项目无关

// AddCreditCardTable Credit Card V1 Migration
var AddCreditCardTable = gormigrate.Migration{
	ID: "v1.AddCreditCardTable",
	Migrate: func(tx *gorm.DB) error {
		return tx.AutoMigrate(&modelJielong.Demo{})
	},
	Rollback: func(tx *gorm.DB) error {
		return tx.Migrator().DropTable(modelJielong.Demo{}.TableName())
	},
}

// AddAgeColumnForUserTable User v2 Migration
var AddAgeColumnForUserTable = gormigrate.Migration{
	ID: "v1.AddAgeColumnForUserTable",
	Migrate: func(tx *gorm.DB) error {
		// when table already exists, it just adds fields as columns
		type YouduJielongUser struct {
			Age int
		}
		// NOTE(fanguiju): 这里可以选择使用 DDL 语句或 AutoMigrate 功能。
		return tx.AutoMigrate(&YouduJielongUser{})
	},
	Rollback: func(tx *gorm.DB) error {
		return tx.Migrator().DropColumn(modelJielong.Demo{}.TableName(), "age")
	},
}
